package com.example.house.common.bean;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zengyz
 * @date 2018-01-01
 * 返回结果定义
 */
public class Result extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    public Result() {
        put("code", 200);
    }

    public static Result error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static Result error(String msg) {
        return error(500, msg);
    }

    public static Result error(int code, String msg) {
        Result ru = new Result();
        ru.put("code", code);
        ru.put("msg", msg);
        return ru;
    }

    public static Result ok(String msg) {
        Result ru = new Result();
        ru.put("msg", msg);
        return ru;
    }

    public static Result ok(Map<String, Object> map) {
        Result ru = new Result();
        ru.putAll(map);
        return ru;
    }

    public static Map page(Map<String, Object> map, Integer page, Integer limit) {
        map.put("offset", (page - 1) * limit);
        map.put("page", page);
        map.put("limit", limit);
        return map;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
